package cn.snmp.mutual.nms;

public class SnmpUnsignedInt extends SnmpVar
{
    protected long numberValue;
    protected byte[] bytesValue;
    
    public SnmpUnsignedInt(final long l) {
        this.numberValue = 0L;
        this.numberValue = l;
        this.Type = 66;
    }
    
    @Override
    int encode(final byte[] bytes, final int i) throws ArrayIndexOutOfBoundsException {
        return ASNTypes.encodeUInt(bytes, i, (int)this.numberValue, 66);
    }
    
    @Override
    public boolean equals(final Object obj) {
        if (obj == null || !(obj instanceof SnmpUnsignedInt)) {
            return false;
        }
        final SnmpUnsignedInt snmpunsignedint = (SnmpUnsignedInt)obj;
        return this.numberValue == snmpunsignedint.longValue();
    }
    
    @Override
    public Object getVarObject() {
        return this.toValue();
    }
    
    public long longValue() {
        return this.numberValue;
    }
    
    @Override
    public byte[] toBytes() {
        if (this.bytesValue == null) {
            this.bytesValue = new byte[4];
            int i = (int)this.numberValue;
            int j = this.bytesValue.length;
            while (i != 0) {
                this.bytesValue[--j] = (byte)(i & 0xFF);
                i >>>= 8;
            }
        }
        return this.bytesValue;
    }
    
    @Override
    public String toString() {
        return Long.toString(this.numberValue);
    }
    
    @Override
    public String toTagString() {
        return "UNSIGNED : " + Long.toString(this.numberValue);
    }
    
    @Override
    public Object toValue() {
        return new Long(this.numberValue);
    }
}
